package com.hmkj.web.controller.my;

import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.page.BasePageParams;
import com.hmkj.common.page.Pages;
import com.hmkj.core.mapper.amount.PointLogMapper;
import com.hmkj.core.po.user.PointLog;
import com.hmkj.core.po.user.User;
import com.hmkj.core.service.amount.PointLogService;
import com.hmkj.web.controller.GenericController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(description = "积分明细相关")
@Slf4j
@RestController
@RequestMapping(GenericController.MEMBER_URL + "/point")
public class MyPointController extends GenericController<Integer, PointLog>{

    @Resource
    private PointLogService pointLogService;

    @ApiOperation(value = "个人中心-积分明细", notes = "积分明细")
    @ResponseBody
    @RequestMapping(value = "log", method = RequestMethod.POST)
    public ResultEntity<Pages<PointLog>> accountLogList(@ModelAttribute BasePageParams basePageParams) {
        User user = getLoginUser();
        Map<String, Object> param = new HashMap<>();
        param.put("userId", user.getId());
        param.put("basePageParams", basePageParams);
        Pages<PointLog> pages = pointLogService.selectByPage(basePageParams,
                q -> ((PointLogMapper) q).findCountForPointLogList(param),
                q -> ((PointLogMapper) q).findListForPointLoList(param));
        return ok(pages);
    }
}
